package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BusInsomniaAlertMapper;
import com.ruoyi.system.domain.BusInsomniaAlert;
import com.ruoyi.system.service.IBusInsomniaAlertService;
import com.ruoyi.common.core.text.Convert;

/**
 * 失眠预警Service业务层处理
 *
 * @author wuxiao
 * @date 2025-09-29
 */
@Service
public class BusInsomniaAlertServiceImpl implements IBusInsomniaAlertService
{
    @Autowired
    private BusInsomniaAlertMapper busInsomniaAlertMapper;

    /**
     * 查询失眠预警
     *
     * @param id 失眠预警主键
     * @return 失眠预警
     */
    @Override
    public BusInsomniaAlert selectBusInsomniaAlertById(Integer id)
    {
        return busInsomniaAlertMapper.selectBusInsomniaAlertById(id);
    }

    /**
     * 查询失眠预警列表
     *
     * @param busInsomniaAlert 失眠预警
     * @return 失眠预警
     */
    @Override
    public List<BusInsomniaAlert> selectBusInsomniaAlertList(BusInsomniaAlert busInsomniaAlert)
    {
        return busInsomniaAlertMapper.selectBusInsomniaAlertList(busInsomniaAlert);
    }

    /**
     * 新增失眠预警
     *
     * @param busInsomniaAlert 失眠预警
     * @return 结果
     */
    @Override
    public int insertBusInsomniaAlert(BusInsomniaAlert busInsomniaAlert)
    {
        if(busInsomniaAlert.getUserId()==null){
            Long userId = ShiroUtils.getUserId();
            busInsomniaAlert.setUserId(userId);
        }
        if(busInsomniaAlert.getRecordId()==null){
            busInsomniaAlert.setRecordId(1);
        }
        busInsomniaAlert.setCreateTime(DateUtils.getNowDate());
        return busInsomniaAlertMapper.insertBusInsomniaAlert(busInsomniaAlert);
    }

    /**
     * 修改失眠预警
     *
     * @param busInsomniaAlert 失眠预警
     * @return 结果
     */
    @Override
    public int updateBusInsomniaAlert(BusInsomniaAlert busInsomniaAlert)
    {
        busInsomniaAlert.setUpdateTime(DateUtils.getNowDate());
        return busInsomniaAlertMapper.updateBusInsomniaAlert(busInsomniaAlert);
    }

    /**
     * 批量删除失眠预警
     *
     * @param ids 需要删除的失眠预警主键
     * @return 结果
     */
    @Override
    public int deleteBusInsomniaAlertByIds(String ids)
    {
        return busInsomniaAlertMapper.deleteBusInsomniaAlertByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除失眠预警信息
     *
     * @param id 失眠预警主键
     * @return 结果
     */
    @Override
    public int deleteBusInsomniaAlertById(Integer id)
    {
        return busInsomniaAlertMapper.deleteBusInsomniaAlertById(id);
    }
}
